package com.elong.businesstravel.modules.member.adapter;

import java.util.List;

import com.elong.businesstravel.R;
import com.elong.businesstravel.entitys.MessageNotice;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

/**
 * 消息中心
 * 
 * @author lenovo
 * 
 */
public class MessageCenterAdapter extends BaseAdapter {

	private Context mContext;
	private List<MessageNotice> mMessageNoticeList;

	public MessageCenterAdapter(Context context,
			List<MessageNotice> messageNotices) {
		mContext = context;
		mMessageNoticeList = messageNotices;
	}

	@Override
	public int getCount() {
		return mMessageNoticeList.size();
	}

	@Override
	public Object getItem(int arg0) {
		return mMessageNoticeList.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		return arg0;
	}

	@Override
	public View getView(int arg0, View arg1, ViewGroup arg2) {

		if (null == arg1) {
			arg1 = LayoutInflater.from(mContext).inflate(
					R.layout.adapter_message_center, null);
		}

		MessageNotice messageNotice = mMessageNoticeList.get(arg0);

		ViewGroup leftLayout = (ViewGroup) arg1.findViewById(R.id.leftLayout);
		TextView leftTitleTextView = (TextView) arg1
				.findViewById(R.id.leftTitleTextView);
		TextView leftDateTextView = (TextView) arg1
				.findViewById(R.id.leftDateTextView);
		
		ViewGroup rightLayout = (ViewGroup) arg1.findViewById(R.id.rightLayout);
		TextView rightTitleTextView = (TextView) arg1
				.findViewById(R.id.rightTitleTextView);
		TextView rightDateTextView = (TextView) arg1
				.findViewById(R.id.rightDateTextView);
		
		if (arg0 % 2 == 0) {
			leftLayout.setVisibility(View.VISIBLE);
			rightLayout.setVisibility(View.GONE);
			leftTitleTextView.setText(messageNotice.msg);
			leftDateTextView.setText(messageNotice.addtime);
		} else {
			leftLayout.setVisibility(View.GONE);
			rightLayout.setVisibility(View.VISIBLE);
			rightTitleTextView.setText(messageNotice.msg);
			rightDateTextView.setText(messageNotice.addtime);
		}

		return arg1;
	}

}
